<?php

function PreloadingStart($target)
{
	global $blogURL, $pluginURL, $configVal;

//	$url = urlencode(getenv("REQUEST_URI"));
//	$authorized = doesHaveOwnership();
	requireComponent('Textcube.Function.misc');
	$data = setting::fetchConfigVal( $configVal);

	if (is_null($data))
	{
		$data['imgStyle'] = "01";
	}

	list($pl_width, $pl_height, $pl_type, $pl_attr) = getimagesize(ROOT . "/plugins/Preloading/loading_" . $data['imgStyle'] . ".gif");

	$image = '<img src="' . $pluginURL . '/loading_' . $data['imgStyle'] . '.gif" ' . $pl_attr . ' border="0" alt="Loading..." />';
	
	$target .= '

<script type="text/javascript">
function PL_load_css()
{
	var pagesize = PL_getPageSize(); 
	document.write("<style type=\"text/css\">.PL_load { position:absolute; left:" + (pagesize[0] - ' . $pl_width . ') / 2 + "px; top:" + (pagesize[1] - ' . $pl_height . ') / 2 + "px; display:block; }</style>");
}

function PL_getPageSize()
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

PL_load_css();
</script>

';
	$target .= "<div align=\"center\" id=\"PL_load\" class=\"PL_load\">$image</div>\n<div id=\"TT_Body\" style=\"display:none\">\n";

	return $target;
}

function PreloadingEnd($target)
{
	$target .= "</div>\n";
	$target .= <<<SCR

<script type="text/javascript">
	document.getElementById('PL_load').style.display = "none";
	document.getElementById('TT_Body').style.display = "block";
</script>

SCR;
	return $target;
}

function PreloadingConfig($plugin)
{
	global $service;
	
	$pluginURL = $service['path'] . "/plugins/" . $plugin;

	$manifest = NULL;
	
	$manifest .= '<?xml version="1.0" encoding="utf-8"?>' . CRLF;
	$manifest .= '<config dataValHandler="">' . CRLF;
	$manifest .= '	<window width="500" height="310" />' . CRLF;
	$manifest .= '		<fieldset legend="Preloading 選項">' . CRLF;
	$manifest .= '		<field title="圖片樣式" name="imgStyle" type="select">' . CRLF;
	$manifest .= '			<op value="01" checked="checked">Style #1</op>' . CRLF;
	$manifest .= '			<op value="02">Style #2</op>' . CRLF;
	$manifest .= '			<op value="03">Style #3</op>' . CRLF;
	$manifest .= '			<op value="04">Style #4</op>' . CRLF;
	$manifest .= '			<op value="05">Style #5</op>' . CRLF;
	$manifest .= '			<op value="06">Style #6</op>' . CRLF;
	$manifest .= '			<op value="07">Style #7</op>' . CRLF;
	$manifest .= '			<op value="08">Style #8</op>' . CRLF;
	$manifest .= '			<caption>' . CRLF;
	$manifest .= '				<![CDATA[' . CRLF;
	$manifest .= '				<strong>圖片樣式預覽</strong><br /><br />' . CRLF;
	$manifest .= '				<p>' . CRLF;
	$manifest .= '					<strong>Style #1</strong>  <img src="' . $pluginURL . '/loading_01.gif" alt="style #1" border="0" align="absmiddle" />&nbsp;&nbsp;&nbsp;&nbsp;' . CRLF;
	$manifest .= '					<strong>Style #2</strong>  <img src="' . $pluginURL . '/loading_02.gif" alt="style #2" border="0" align="absmiddle" />&nbsp;&nbsp;&nbsp;&nbsp;' . CRLF;
	$manifest .= '					<strong>Style #3</strong>  <img src="' . $pluginURL . '/loading_03.gif" alt="style #3" border="0" align="absmiddle" />&nbsp;&nbsp;&nbsp;&nbsp;' . CRLF;
	$manifest .= '					<strong>Style #4</strong>  <img src="' . $pluginURL . '/loading_04.gif" alt="style #4" border="0" align="absmiddle" /><br />' . CRLF;
	$manifest .= '					<strong>Style #5</strong>  <img src="' . $pluginURL . '/loading_05.gif" alt="style #5" border="0" align="absmiddle" /><br />' . CRLF;
	$manifest .= '					<strong>Style #6</strong>  <img src="' . $pluginURL . '/loading_06.gif" alt="style #6" border="0" align="absmiddle" /><br />' . CRLF;
	$manifest .= '					<strong>Style #7</strong>  <img src="' . $pluginURL . '/loading_07.gif" alt="style #7" border="0" align="absmiddle" /><br />' . CRLF;
	$manifest .= '					<strong>Style #8</strong>  <img src="' . $pluginURL . '/loading_08.gif" alt="style #8" border="0" align="absmiddle" /><br />' . CRLF;

	$manifest .= '				</p>' . CRLF;
	$manifest .= '				]]>' . CRLF;
	$manifest .= '			</caption>' . CRLF;
	$manifest .= '		</field>' . CRLF;
	$manifest .= '	</fieldset>' . CRLF;
	$manifest .= '</config>';
	
	return $manifest;
}

?>
